<template>
	<view class="package-list">
		<view class="tabs">
			<u-tabs
				:list="classList"
				:current="classIndex"
				@change="classChange"
				active-color="#141414"
				inactive-color="#666666"
				name="style_name"
				height="104">
			</u-tabs>
		</view>
		<view class="package-items">
			<view class="package-item" v-for="(data,index) in list" :key="index" @click="goInfo(data)">
				<image class="package-img" :src="data.image" mode="aspectFill"></image>
				<image class="package-tag" mode="widthFix" src="https://jiajudashi.oss-cn-shenzhen.aliyuncs.com/static/images/other/2022-08-26/20220826/8df3973244634314fd8f4238c2ef3e6e.png"></image>
				<scroll-view scroll-x class="package-goods">
					<view class="package-goods-box">
						<image class="goods-img" v-for="(item,i) in data.image_list" :key="i" :src="item" mode="aspectFill"></image>
					</view>
				</scroll-view>
				<view class="package-name">{{data.group_name}}</view>
				<view class="package-price">
					<view class="price">
						<view class="rela-price">￥<text>{{data.retail_price}}</text></view>
						<view class="del-price">原价：<text>￥{{data.market_price}}</text></view>
					</view>
					<view class="des">共{{data.image_list.length}}件商品</view>
				</view>
			</view>
		</view>
		<pt-nothing
			text="暂无特价套餐" 
			:fixed="true" 
			v-if="noMore && !list.length" 
			icon="https://jiajudashi.oss-cn-shenzhen.aliyuncs.com/images/shop/icons/nothing.png?v=1">
		</pt-nothing>
		<pt-loading-more v-if="loadingMore"></pt-loading-more>
		<pt-nomore v-if="noMore && list.length"></pt-nomore>
		<pt-loading></pt-loading>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				classIndex: 0,
				classList: [],
				noMore: false,
				loadingMore: false,
				page: 0,
				style_id: '',
				list: [],
			}
		},
		onReachBottom() {
			if(!this.noMore){
				this.page++
				this.loadingMore = true
				this.init()
			}
		},
		onLoad() {
			this.init()
		},
		methods: {
			async init(){
				this.$u.api.GroupList({is_house: 3,page: this.page,style_id: this.style_id, order_by: 'sort', asc: 2}).then(res => {
					this.loadingMore = false
					if(!this.classList.length){
						this.classList = res.datas.style_list
					}
					let user_id = uni.getStorageSync('userInfo')?JSON.parse(uni.getStorageSync('userInfo')).user_id:0
					if(res.datas.list.length){
						res.datas.list.forEach(item => {
							this.list.push(item)
						})
						this.$u.mpShare = {
							title: '特价套餐',
							path: '/special-package/list/list?parent_id=' + user_id,
							imageUrl: this.list[0].image
						}
					}else{
						this.noMore = true
					}
				})
			},
			classChange(e){
				this.classIndex = e
				this.noMore = false
				this.list = []
				this.page = 0
				this.style_id = this.classList.length?this.classList[this.classIndex].style_id:''
				this.init()
			},
			goInfo(data){
				uni.navigateTo({
					url: `/special-package/info/info?group_id=${data.group_id}`
				})
			}
		}
	}
</script>

<style lang="scss">
	.package-list{
		padding-top: 104rpx;
		.tabs{
			border-bottom: solid 2rpx #F7F7F7;
			position: fixed;
			top: 0;
			left: 0;
			right: 0;
			z-index: 100;
			background-color: #FFF;
		}
		.package-items{
			padding: 30rpx 30rpx 0;
			.package-item{
				margin-top: 30rpx;
				box-shadow: 0px 1rpx 40rpx 0px rgba(40,34,31,0.05);
				border-radius: 8rpx;
				overflow: hidden;
				position: relative;
				&:first-child{
					margin-top: 0;
				}
				.package-img{
					width: 100%;
					height: 552rpx;
				}
				.package-tag{
					position: absolute;
					z-index: 1;
					left: 20rpx;
					top: 20rpx;
					width: 172rpx;
				}
				.package-goods{
					.package-goods-box{
						white-space: nowrap;
						padding: 20rpx;
						.goods-img{
							margin-right: 20rpx;
							width: 144rpx;
							height: 144rpx;
							border-radius: 8rpx;
						}
					}
				}
				.package-name{
					padding: 0 20rpx 20rpx;
					font-size: 36rpx;
					font-weight: bold;
					color: #141414;
				}
				.package-price{
					display: flex;
					align-items: center;
					justify-content: space-between;
					padding: 0 20rpx 20rpx;
					.price{
						display: flex;
						align-items: center;
						.rela-price{
							font-size: 25rpx;
							color: #FF4544;
							text{
								font-family: 'din';
								font-size: 38rpx;
								font-weight: bold;
							}
						}
						.del-price{
							margin-left: 20rpx;
							font-size: 22rpx;
							color: #666;
							text-decoration: line-through;
						}
					}
					.des{
						font-size: 22rpx;
						color: #666;
					}
				}
			}
		}
	}
</style>
